let apiErrorTypes = {};
let errorMap = new Map();

/**
 * API错误名称
 */
apiErrorTypes.UNKNOW_ERROR = "unknow error";
apiErrorTypes.NOT_FOUND = "not found";
apiErrorTypes.USER_NOT_EXIST = "user not exist";

/**
 * API错误名称对应的错误信息
 */

errorMap.set(apiErrorTypes.UNKNOW_ERROR, {code: -1, message: '未知错误'});
errorMap.set(apiErrorTypes.NOT_FOUND, {code: 404, message: '未找到相关信息'});
errorMap.set(apiErrorTypes.USER_NOT_EXIST, {code: 101, message: '用户不存在'});

//根据错误名称获取错误信息
apiErrorTypes.getErrorInfo = (name) => {
	let error;

	if (name) {
		error = errorMap.get(name);
	}

	//如果没有对应的错误信息，默认'未知错误'
	if (!error) {
		name = apiErrorTypes.UNKNOW_ERROR;
		error = errorMap.get(name);
	}

	return error;
};

module.exports = apiErrorTypes;
